package com.xmy.study.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmy.study.entity.AdmOrganization;
import com.xmy.study.service.IAdmOrganizationService;
import com.xmy.study.util.Code;
import com.xmy.study.util.PageResult;
import com.xmy.study.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/admin/admOrganization")
public class AdmOrganizationController {
    @Autowired
    @Lazy
    IAdmOrganizationService iAdmOrganizationService;

    @GetMapping("list")
    @ApiOperation("校区列表")
    public Result getList(@RequestParam Map<String, String> reMap) {
        int pageNum = reMap.get("pageNum") != null && !reMap.get("pageNum").isEmpty() ? Integer.parseInt(reMap.get("pageNum")) : 1;
        int pageSize = reMap.get("pageSize") != null && !reMap.get("pageSize").isEmpty() ? Integer.parseInt(reMap.get("pageSize")) : 10;
        Page<AdmOrganization> iPage = new Page<>(pageNum, pageSize);

        QueryWrapper<AdmOrganization> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        iAdmOrganizationService.page(iPage, queryWrapper);

        return new Result(Code.GET_OK, new PageResult<>(iPage.getRecords(), iPage.getTotal(), iPage.getPages()), Code.GET_OK_MSG);
    }

}
